package cn.attackme.myuploader.service.impl;

import cn.attackme.myuploader.service.SectionUploadService;
import cn.attackme.myuploader.utils.QCloudCosUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
@Service
public class SectionUploadServiceImpl implements SectionUploadService {

    @Autowired
    private QCloudCosUtils qCloudCosUtils;
    @Override
    public String upload( String path) {
        readAllFile(path);

        return "OK";
    }
    public  void readAllFile(String filepath){
        File file = new File(filepath);
        if (!file.isDirectory()) {
            qCloudCosUtils.upload(file,filepath);

        } else if (file.isDirectory()) {

            String[] filelist = file.list();
            for (int i = 0; i < filelist.length; i++) {

                File readfile = new File(filepath + "/" +filelist[i]);

                if (!readfile.isDirectory()) {
                    qCloudCosUtils.upload(readfile,filepath+"/"+filelist[i]);

                } else if (readfile.isDirectory()) {

                    readAllFile(filepath + "/" + filelist[i]);//递归
                }
            }
        }
    }

}
